Imports LookUp
Imports DAOMain
Imports System.Data

Partial Class WebForms_CInfo_Other
    Inherits WebFormCommon

    Dim strPath As String

    Private Sub SetPageSecurity()
        Dim sec As New Secure
        Dim cfunc As New CIMSfunc

        sec.ParentPage = Parentpage

        sec.SetPageAccess(Session("UserName"))

        If ViewState("mode") = "view" Then
            cfunc.FormDisable(divMain)
        End If

        cfunc = Nothing
        sec = Nothing

    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Select Case PageControlMode
            Case ControlMode.NewBusiness
                strPath = "New_Business"
            Case ControlMode.ClientServicing
                strPath = "Client_Servicing"
        End Select

        If Not Page.IsPostBack Then
            Dim lookup As New LookUp.FillLookUp

            With lookup
                .FillDropDown(IDType_cmb, FillLookUp.eLookUpType.other, "ID_TYPE")
                .FillDropDown(SmokingStatus_cmd, FillLookUp.eLookUpType.other, "SMOKING_STATUS")
                .FillDropDown(Funds_cmb, FillLookUp.eLookUpType.other, "SOURCE_FUND")
            End With

            lookup = Nothing

            Call InitVars()

            Policy_td.InnerText = ViewState("PolicyNo")
            Provider_td.InnerText = ViewState("Provider")
            Name_td.InnerText = ViewState("CName")
            Call SetPageSecurity()

            Call LoadDetails()

            Dim sec As New Secure

            sec.ParentPage = ParentPage

            If IsNothing(ViewState("CID")) Then
                sec.AddControl(Save_btn, Secure.ControlTypes.AddType)
            Else
                sec.AddControl(Save_btn, Secure.ControlTypes.EditType)
            End If

            sec.SetPageAccess(Session("UserName"))
            sec = Nothing
        End If
    End Sub

    Private Sub LoadDetails()
        Dim dao As New DAOMain.POLICY_CLIENT_DTL_DAO_OTHER
        Dim vo As New DAOMain.POLICY_CLIENT_DTL_VO_OTHER

        vo.POLICY_SEQ_CD = ViewState("Seq_CD")
        vo.POLICY_CLIENT_CD = ViewState("CID")

        Dim dt As DataTable = dao.Search(vo)

        If dt.Rows.Count > 0 Then
            With dt.Rows(0)
                On Error Resume Next
                Occupation_txt.Text = .Item("OCCUPATION")
                Position_txt.Text = .Item("POLICY_CLIENT_POSITION")
                business_nature_txt.Text = .Item("BUSINESS_NATURE")
                Remarks_txt.Text = .Item("REMARKS")
                IDType_cmb.SelectedValue = .Item("ID_TYPE")
                IDNo_txt.Text = .Item("ID_NO")
                SmokingStatus_cmd.SelectedValue = .Item("SMOKE_ST")
                Funds_cmb.SelectedValue = .Item("SOURCE_FUND")

            End With
        End If

        dao = Nothing
        vo = Nothing
    End Sub

    Protected Sub Save_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Save_btn.Click
        Dim dao As New DAOMain.POLICY_CLIENT_DTL_DAO_OTHER
        Dim vo As New DAOMain.POLICY_CLIENT_DTL_VO_OTHER
        Dim mFunc As New PolyFunc.ASPFunc

        With vo
            .POLICY_SEQ_CD = ViewState("Seq_CD")
            .POLICY_CLIENT_CD = ViewState("CID")
            .OCCUPATION = Occupation_txt.Text
            .POLICY_CLIENT_POSITION = Position_txt.Text
            .BUSINESS_NATURE = business_nature_txt.Text
            .REMARKS = Remarks_txt.Text
            .ID_TYPE = IDType_cmb.SelectedValue.ToString
            .ID_NO = IDNo_txt.Text
            .SMOKE_ST = SmokingStatus_cmd.SelectedValue.ToString
            .POLICY_CLIENT_LAST_UPD_BY = Session("UserName")
            .POLICY_CLIENT_LAST_UPD_DT = Now
            .SOURCE_FUND = Funds_cmb.SelectedValue.ToString
        End With

        If dao.Update(vo) Then
            mFunc.MessageAlert(ParentPage, "Record Saved!")
        Else
            mFunc.MessageAlert(ParentPage, "Error Saving Record!")
        End If

        mFunc = Nothing
        dao = Nothing
        vo = Nothing
    End Sub

    Protected Sub Correspondence_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Correspondence_btn.Click
        InitSessions()
        Response.Redirect("~/" & strpath & "/Add_CInfo_Cor.aspx")
    End Sub

    Protected Sub Main_Info_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Main_Info_btn.Click, Cancel_btn.Click
        InitSessions()
        Response.Redirect("~/" & strpath & "/Add_CInfo.aspx")
    End Sub

    Protected Sub Risk_Profile_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Risk_Profile_btn.Click
        InitSessions()
        Response.Redirect("~/" & strpath & "/Add_CInfo_Risk.aspx")
    End Sub

    Protected Sub Attachments_btn_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Attachments_btn.Click
        InitSessions()
        Response.Redirect("~/" & strpath & "/Add_CInfo_Att.aspx")
    End Sub
End Class
